package com.shxy.entity.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.shxy.util.converter.AbstractEnumConverter;
import com.shxy.util.converter.IEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.lang.Nullable;

/**
 * 培训级别
 */
@Getter
@AllArgsConstructor
public enum LevelEnum implements IEnum<String> {
    XUEXIAO("01", "校级"),
    SHI("02","市级"),
    SHENGBU("03","省部级"),
    GUOJIA("04","国家级")
    ;
    private String code;
    private String name;

    /**
     * 类型转换器
     */
    public static class Converter extends AbstractEnumConverter<LevelEnum, String> {
        public Converter() {
            super(LevelEnum.class);
        }
    }

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    @Nullable
    public static LevelEnum resolve(String name) {
        for(LevelEnum levelEnum: LevelEnum.values()) {
            if(name.equals(levelEnum.getName())){
                return levelEnum;
            }
        }
        return null;
    }
}
